<?php
class Product_Model_PackageMap
{

	private $_table;
	//Initalizing Db Table  
	public function __construct(){
		$this->_table = new Product_Model_DbTable_PackageMap();
	}
	
	public function getByProductIdAndWarehouseId($productId,$warehouseId){
		$select = $this->_table->select()->where("product_id = ?",$productId);
		$select->where("warehouse_id = ?",$warehouseId);
		return $this->_table->fetchRow($select);
	}
	
	public function getByProductId($productId){
		$select = $this->_table->select()->where("product_id = ?",$productId);
		return $this->_table->fetchRow($select);
	}
	
	public function add($row){
		$row['ppm_last_update'] = date("Y-m-d H:i:s");
		return $this->_table->insert($row);
	}
	public function update($row,$id){
		$row['ppm_last_update'] = date("Y-m-d H:i:s");
		$where = $this->_table->getAdapter()->quoteInto("ppm_id = ?",$id);
		return $this->_table->update($row,$where);
	}
	
	public function getByValue($value,$field){
        $select = $this->_table->getAdapter()->select();
        $table  = $this->_table->info('name');
        $select->from($table,'*');
        $select->where("{$field} = ?",$value);
		return $this->_table->getAdapter()->fetchRow($select);
	}
	
}